<div class="box">
    <div class="heading">
        <h1>
            <img alt="" src="<?php echo base_url('assets/admin/images/layout.png'); ?>">Widget 
            
        </h1>

        <div class="buttons">
            <a class="button" href="javascript:void(0);" id="save"><span>Save</span></a>
            <a class="button" href="javascript:void(0);" id="save_exit"><span>Save &amp; Exit</span></a>
            <a class="button" href="<?php echo base_url(ADMIN_PATH . '/tools/widgets'); ?>"><span>Cancel</span></a>
        </div>
    </div>
    <div class="content">

        <?php echo form_open('', 'id="widget_add"'); ?>
        <div class="form">
            <div>
                <?php echo form_label('<span class="required">*</span> Widget Title', 'title'); ?>
                <?php echo form_input(array('name' => 'title', 'id' => 'title', 'value' => set_value('widget',!empty($widgets['title']) ? $widgets['title'] : ''))); ?>
				&nbsp;<span class="help" style="display: inline-block;"><?php echo form_error('title'); ?></span>
            </div>
            <div>
                <?php echo form_label('<span class="required">*</span>Widget Short Name:', 'short_name'); ?>
                <?php echo form_input(array('name' => 'short_name', 'id' => 'short_name', 'value' => set_value('widget',!empty($widgets['short_name']) ? $widgets['short_name'] : ''))); ?>
            </div>
			<div>
                <?php echo form_label('<span class="required">*</span>Widget Height:', 'widget_height'); ?>
                <?php echo form_input(array('name' => 'widget_height', 'id' => 'widget_height', 'value' => set_value('widget',!empty($widgets['widget_height']) ? $widgets['widget_height'] : ''))); ?>
            </div>
			<div>
                <?php echo form_label('<span class="required">*</span>Widget Hidth:', 'widget_width'); ?>
                <?php echo form_input(array('name' => 'widget_width', 'id' => 'widget_width', 'value' => set_value('widget',!empty($widgets['widget_width']) ? $widgets['widget_width'] : ''))); ?>
            </div>
			<div>
				<?php echo form_label('<span class="required">*</span> Widget Type:', 'widget_type'); ?>
				<?php echo form_dropdown('widget_type', array(''=>'select Widget Type','video'=>'video', 'custom'=>'custom'), set_value('widget Type',!empty($widgets['widget_type']) ? $widgets['widget_type'] : ''), 'id=\'widget_type\'')?>
				&nbsp;<span id="widget_message" class="help" style="display: inline;"></span>
			</div>
			
			<div>
				<?php echo form_label('Widget Content:', 'widget_content'); ?>
				<?php echo form_textarea(array('name'=>'widget_content', 'id'=>'widget_content','class'=>'ckeditor_textarea', 'style'=>'height: 200px;','value'=>set_value('widget_content',!empty($widgets['widget_content']) ? stripslashes($widgets['widget_content']) : ''))); ?>
			</div>
        </div>
        
        
        <?php echo form_close(); ?>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
	$('textarea.ckeditor_textarea').each(function(index)
	{
			ckeditor_config.height = $(this).height();
			CKEDITOR.replace('widget_content', ckeditor_config); 
	});
		     
		// Auto Generate Url Title
		$('#title').keyup( function(e) {
			$('#short_name').val($(this).val().toLowerCase().replace(/\s+/g, '_').replace(/[^a-z0-9\-_]/g, ''))
		});
		$('#widget_type').change(function() {
			var widget_type=$(this).val();
			if(widget_type=="video")
			{
				$("#widget_message").text("Add only youtube,vimeo video url in widget content area");
			}
			else
			{
				$("#widget_message").text("Any content in widget content area");
			}
		});
		
        // Save Content
        $("#save, #save_exit").click( function() {
            if ($(this).attr('id') == 'save_exit')
            {
                $('<input>').attr({
                    type: 'hidden',
                    name: 'save_exit',
                    value: '1'
                }).appendTo('#widget_add');

                $('#widget_add').submit();
            }
            else
            {
                $('#widget_add').submit();
            }
        });
    });
</script>

